package com.bml.architect.rabbitmq.topics;

import com.bml.architect.rabbitmq.utils.RabbitConstant;
import com.bml.architect.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Sina {

    public static void main(String[] args) throws Exception {
        Connection connection = RabbitUtils.getConnection();

        final  Channel channel = connection.createChannel();

        channel.queueDeclare(RabbitConstant.sina_queue,false,false,false,null);

        channel.queueBind(RabbitConstant.sina_queue,RabbitConstant.exchange_weather_topic,"sc.#");

        channel.basicQos(1);
        channel.basicConsume(RabbitConstant.sina_queue,false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("新浪接受到的天气为：" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
